package cn.jsp;

import java.io.*;

import cn.jsp.dao.StuDao;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
    private String message;

    public void init() {
        message = "Hello World!";
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
        response.setContentType("text/html");

        // Hello
        PrintWriter out = response.getWriter();
        WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
        StuDao dao=ctx.getBean(StuDao.class);
        out.println(dao.query());
    }

    public void destroy() {
    }
}